<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>menu</title>
    <link media="all" rel="stylesheet" th:href="@{/static/layuimini/lib/layui-v2.6.3/css/layui.css}">

    <link media="all" rel="stylesheet" th:href="@{/static/layuimini/css/public.css}">
    <style>
        .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
            height: 34px;
            line-height: 34px;
            padding: 0 8px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div>
            <div class="layui-btn-group">
                <button class="layui-btn" id="btn-add" style="background-color: #0f50b1;margin-right: 10px">新添</button>
                <button class="layui-btn" id="btn-expand">展开</button>
                <button class="layui-btn layui-btn-normal" id="btn-fold">折叠</button>
            </div>
            <table class="layui-table" id="munu-table" lay-filter="munu-table"></table>
        </div>
    </div>
</div>
<!-- 操作列 -->
<script id="auth-state" type="text/html">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script charset="utf-8" th:src="@{/layuimini/lib/layui-v2.6.3/layui.js}"></script>
<script charset="utf-8" th:src="@{/layuimini/js/lay-config.js?v=1.0.4}"></script>
<script th:inline="javascript">
    var ctx = [[@{/}]];
</script>
<script th:inline="none">

    layui.use(['table', 'treetable'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var treetable = layui.treetable;


        // 渲染表格
        layer.load(2);
        treetable.render({
            treeColIndex: 1,   //树形图显示在第几列
            treeSpid: -1,      //最上级的父级id
            treeIdName: 'authorityId',  //id 字段
            treePidName: 'parentId',     //父级节点
            treeDefaultClose: true,	//是否默认折叠
            treeLinkage: false,		//父级展开时是否自动展开所有子级
            elem: '#munu-table',
            url: ctx + 'systemMenu/menuGuan',
            page: false,
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                console.log(res);
            },
            cols: [[
                {type: 'numbers'},
                {field: 'authorityName', minWidth: 200, title: '权限名称'},
                {field: 'authority', title: '权限标识'},
                {field: 'menuUrl', title: '菜单url'},
                {
                    field: 'menuIcon', title: '图标', templet: function (d) {
                        return ' <i class="' + d.menuIcon + '"></i> ';
                    }
                },
                {
                    field: 'status', width: 80, align: 'center', title: '状态', templet: function (d) {
                        if (d.status === 1) {
                            return '<span class="layui-badge layui-bg-green">显示</span>';
                        } else {
                            return '<span class="layui-badge layui-bg-orange">隐藏</span>';
                        }
                    }
                },
                {field: 'orderNumber', width: 80, align: 'center', title: '排序号'},
                {
                    field: 'isMenu', width: 80, align: 'center', templet: function (d) {
                        if (d.isMenu === 1) {
                            return '<span class="layui-badge layui-bg-orange">按钮</span>';
                        } else if (d.isMenu === -1) {
                            return '<span class="layui-badge layui-bg-blue">导航</span>';
                        } else if (d.isMenu === 2) {
                            return '<span class="layui-badge layui-bg-green">菜单</span>';
                        } else if (d.isMenu === 3) {
                            return '<span class="layui-badge layui-bg-orange">按钮</span>';
                        } else if (d.isMenu === -2) {
                            return '<span class="layui-badge layui-bg-cyan">模块</span>';
                        } else {
                            return '<span class="layui-badge layui-bg-green">菜单</span>';
                        }
                    }, title: '类型'
                },
                {templet: '#auth-state', width: 120, align: 'center', title: '操作'}
            ]],
            //数据渲染完的回调
            done: function () {
                //关闭加载
                layer.closeAll('loading');
            }
        });

        $('#btn-expand').click(function () {
            treetable.expandAll('#munu-table');
        });

        $('#btn-fold').click(function () {
            treetable.foldAll('#munu-table');
        });

        $('#btn-add').click(function () {

            layer.msg('添加');


        })


        //监听工具条
        table.on('tool(munu-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'del') {
                layer.msg('删除' + data.id);
            } else if (layEvent === 'edit') {
                layer.msg('修改' + data.id);
            }
        });
    });
</script>
</body>
</html>